<?php

namespace Database\Seeders;

use App\Models\Category;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class CategorySeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // 清空分类表（使用delete而不是truncate避免外键约束问题）
        DB::table('categories')->delete();

        $categories = [
            [
                'name' => '热菜',
                'slug' => 'hot',
                'description' => '各种热菜类菜品',
                'sort_order' => 1,
                'is_active' => true,
                'dish_count' => 0,
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => '凉菜',
                'slug' => 'cold',
                'description' => '各种凉菜类菜品',
                'sort_order' => 2,
                'is_active' => true,
                'dish_count' => 0,
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => '汤品',
                'slug' => 'soup',
                'description' => '各种汤品类菜品',
                'sort_order' => 3,
                'is_active' => true,
                'dish_count' => 0,
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => '主食',
                'slug' => 'staple',
                'description' => '各种主食类菜品',
                'sort_order' => 4,
                'is_active' => true,
                'dish_count' => 0,
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => '饮品',
                'slug' => 'drink',
                'description' => '各种饮品类',
                'sort_order' => 5,
                'is_active' => true,
                'dish_count' => 0,
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => '甜品',
                'slug' => 'dessert',
                'description' => '各种甜品类',
                'sort_order' => 6,
                'is_active' => true,
                'dish_count' => 0,
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => '小吃',
                'slug' => 'snack',
                'description' => '各种小吃类',
                'sort_order' => 7,
                'is_active' => true,
                'dish_count' => 0,
                'created_at' => now(),
                'updated_at' => now(),
            ],
        ];

        Category::insert($categories);
        
        $this->command->info('已创建 ' . count($categories) . ' 个分类数据');
    }
}